package br.com.sgc.dao;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import br.com.sgc.entities.geral.Agendamento;
import br.com.sgc.entities.medico.Medico;

@Stateless
public class AgendamentoDao extends GenericDao<Agendamento>{


	private static final long serialVersionUID = 5531658594407420528L;
	
	@SuppressWarnings("unchecked")
	public List<Agendamento> findAgendamentosByDate(Date dataInicial, Date dataFinal, Long medicoId, Long idClinica) {
		Criteria criteria = getCriteria(Agendamento.class);
		criteria.add(Restrictions.between("dataAgendamento", dataInicial, dataFinal));
		criteria.add(Restrictions.eq("clinica.id", idClinica));
		if(medicoId != null){
			criteria.add(Restrictions.eq("medico.id", medicoId));
		}
		
		List<Agendamento> list = criteria.list();
		for(Agendamento a: list){
			if(a.getTipoProcedimento() != null)
				a.getTipoProcedimento().toString();
			
			if(a.getPaciente() != null)
				a.getPaciente().toString();
			
			if(a.getTratamento() != null)
				a.getTratamento().toString();
			
			if(a.getMedico() != null)
				a.getMedico().toString();
			
		}
		
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<Agendamento> findAllByMedicoDia(Medico medico, Date date) {
		Criteria criteria = getCriteria(Agendamento.class);
		criteria.add(Restrictions.eq("medico.id", medico.getId()));
		criteria.add(Restrictions.eq("dataAgendamento", date));
		criteria.addOrder(Order.asc("horaAgendamento"));
		List<Agendamento> list = criteria.list();
		for(Agendamento a: list){
			if(a.getPaciente() != null)
				a.getPaciente().toString();
			
		}
		return list;
	}

}
